package models

import (
	"goim-pro/internal/app/repos/base"
	tbl "goim-pro/internal/db"
)

const (
	StsPending  OperationStatus = "PENDING"
	StsSent     OperationStatus = "SENT"
	StsCancel   OperationStatus = "CANCEL"
	StsReceived OperationStatus = "RECEIVED"

	StsOverwrite OperationStatus = "OVERWRITE" // 重复操作
)

const (
	TypeOfRequest int32 = iota
	TypeOfAccept
	TypeOfReject
	TypeOfDelete
)

type OperationStatus string

type ContactOperation struct {
	OpsId         string          `json:"opsId" gorm:"column:opsId; type:varchar(32); primary_key; not null"`
	RelationId    string          `json:"relationId" gorm:"column:relationId; type:varchar(32); not null"` // A + B 联系人操作集合的唯一Id
	SenderId      string          `json:"senderId" gorm:"column:senderId; type:varchar(32); not null"`
	RecipientId   string          `json:"recipientId" gorm:"column:recipientId; type:varchar(32); not null"`
	OperationType int32           `json:"optType" gorm:"column:optType; type:tinyint(1); not null"`    // 会话类型: 请求添加，拒绝添加，删除 etc..
	Reason        string          `json:"reason" gorm:"column:reason; type:varchar(255); default: ''"` // 操作理由，对联系人添加、删除有效
	Status        OperationStatus `json:"status" gorm:"column:status; type:varchar(20); not null"`
	Sender        User            `gorm:"ForeignKey:senderId"`
	Recipient     User            `gorm:"ForeignKey:recipientId"`
	base.BaseModel
}

func (ContactOperation) TableName() string {
	return tbl.TableContactOperations
}
